﻿using UnityEngine;
using System.Collections;

namespace Stage{
	public class GTools : MonoBehaviour {
		/// <summary>
		/// 传入手势位置 转换成世界坐标
		/// 手势(0,0)对应屏幕左下角
		/// </summary>
		/// <returns>The screen point to word.</returns>
		static public Vector3 CameraScreenPointToWord(Vector3 point,float length){
			Vector3 p = Camera.main.ScreenToViewportPoint (new Vector3 (point.x, point.y, length));
			Vector3 newpos = Camera.main.ViewportToWorldPoint (p);
			return newpos;
		}

		static public Vector3 GetRandomScreenPointToWorld(Vector2 clamp,float length = 1){
//			Rect rect = new Rect ();
			float screenCW = Screen.width * clamp.x;
			float screenCH = Screen.height * clamp.y;
			Vector3 point =new Vector3(Random.Range (screenCW, Screen.width - screenCW),Random.Range(screenCH,Screen.height - screenCH),0);
			return CameraScreenPointToWord (point, length);
		}
		static public string ObjectsToString(object[] objs){
			System.Text.StringBuilder sb = new System.Text.StringBuilder ();
			for (int i = 0; i < objs.Length; i++) {
				sb.Append (objs [i].ToString () + " , ");
			}
			return sb.ToString ();
		}
		static public Vector3 GetRandomPointInRect(Rect rect,float length = 0){
			float x;
			float y;
			float z;
			x = Random.Range (rect.x, rect.width);
			y = Random.Range (-length, length);
			z = Random.Range (rect.y, rect.height);
			Vector3 pos = new Vector3 (x,y,z);
			return pos;
		}
	}
}
